const { onMsg } = require(`${process.root}/util`);
const wol = require('wol');
const reg = /唤醒\s+?(?<mac>(([0-9A-Fa-f]{2})([:-]|$)){6})/;
module.exports = {
  name: 'wake-on-lan',
  main: ({ data }) => {
    onMsg(data, async msg => {
      const res = reg.exec(msg);
      if (!res) return;
      const mac = res?.groups?.mac;
      if (!mac) return { message: 'wake-on-lan: MAC地址错误' };
      const addr = mac.replace(/-/g, ':');
      const waked = await wol.wake(addr);
      return { message: waked ? 'wake-on-lan: 唤醒成功' : 'wake-on-lan: 唤醒失败' }

    }, { checkAdmin: true })
  }
}
